<style src="./formValidation.scss" lang="scss"></style>


<template>
    <div>
        <slot></slot>
    </div>
</template>

<script>
    import rules from "./rules.js";
    import defaults from 'lodash/defaults';
    import {addClass,hasClass,removeClass} from 'utils'

    export default {
        name: "validateGroup",
        props:{
            value:{},
            labelWidth:{
                type:[String,Number],
                default: 100,
            },
            fieldWidth:{
                type:[String,Number],
                default: 'auto',
            },
            extRules:{
                type:[Function,Object],
            },
            root:{
                type: Object,
            }
        },
        data(){
            return {
                name:"validateGroup",
            }
        },
        computed:{
            rules(){
                return defaults(this.extRules,rules)
            }
        },
        methods:{
            TestfiyField(){
                var flag = false;
                this.$children.map((c,i)=>{
                    if(c.name=="validateField"){
                        if(c.status!=2){
                            flag = true;
                        }
                    }
                })
                this.$emit("input",flag)
                return flag;
            },
            ValiWholeField(){
                var blocks = [];
                this.$children.map((c,i)=>{
                    if(c.name=="validateField"){
                        if(c.Validate()){
                            blocks.push(c)
                        }
                    }
                })
                //收集错误添加振动类
                if(blocks.length>0){
                    blocks[0].ScrollShake()
                    return true;
                }
                return false;
            }
        }
    }
</script>